var zlayerIndex = null,
    zBaseUrl = '',
    layerLoad = null;

/**
 * 自定义事件
 * @author zhanghao
 * @type {{regist, fire, remove}}
 */
/**
 * 封装的ajax函数，可以防止二次点击功能
 * @param data  要传过来的数据 json
 * @param callback 成功的函数 fn
 * @param async  异步还是同步  默认异步
 */

function ajaxdata(option, data, callback) {
    var _lodingIndex = null;

    /*if (!ajaxdata.obj) {
     ajaxdata.obj = {};
     }*/

    /*zhanghao 暂时关闭*/
    layer.close(_lodingIndex);

    if (option.isLoding != -1) {
        setTimeout(function () {
            _lodingIndex = lodingDom();
        }, 1);
    }

    //定义发送头
    if (!option.contentType) {
        option.contentType = 'application/x-www-form-urlencoded;charset=utf-8';
    } else {
        if (option.contentType.toLowerCase() == 'json') {
            option.contentType = 'application/json';
        }
    }

    // layerLoad = layer.load(2);

    /*var _str = JSON.stringify(data);

     if (ajaxdata.obj[_str]) {
     _lodingIndex = lodingDom()
     return;
     } else {
     ajaxdata.obj[_str] = _str;
     }*/

    $.ajax({
        type: option.type ? option.type : 'POST',
        url: option.url,
        data: data,
        async: option.async ? false : true, //异步为true，同步false
        contentType: option.contentType,
        dataType: "json",
        timeout: option.timeout ? option.timeout : 50000, //超时时间设置，单位毫秒
        success: function (data) {
            // layer.close(layerLoad);
            setTimeout(function () {
                layer.close(_lodingIndex);
            }, 1);
            if (data.logon_error) {
                logoOutMsg(data.msg, null, function () {
                    window.location.href = zBaseUrl + "user/index.do";
                });
            }
            callback(data.result, data);
            //ajaxdata.obj[_str] = null;
        },
        error: function (xhr, type, exception) {
            // layer.close(layerLoad);
            setTimeout(function () {
                layer.close(_lodingIndex);
            }, 1);
            // callback('404', JSON.stringify(xhr));
            callback(false, {msg: "请求超时"});
            //ajaxdata.obj[_str] = null;
        }
    });
};
var observer = (function () {
    //防止消息队列暴露而被篡改股将消息容器作为静态私有变量保存
    var __messages = {};
    return {
        getMessages:function(){
            return __messages;
        },
        //注册信息接口
        regist: function (type, fn) {
            if (typeof __messages[type] === "undefined") {
                __messages[type] = [fn];
            } else {
                __messages[type].push(fn);
            }
        },
        //发布信息接口
        fire: function (type, args) {
            if (!__messages[type]) {
                return;
            }
            var events = {
                    type: type,
                    args: args || {}
                },
                i = 0,
                len = __messages[type].length;
            for (; i < len; i++) {
                __messages[type][i].call(this, events);
            }
        },
        //移除信息接口
        remove: function (type, fn) {
            if (__messages[type] instanceof Array) {
                var i = __messages[type].length - 1;
                for (; i > 0; i--) {
                    __messages[type][i] === fn && __messages[type].splice(i, 1);
                }
            }
        }
    }
})();
/***验证姓名（中文英文数字下划线）****/
function testName(val) {
    var _reg = /^[A-Za-z_\u4e00-\u9fa50-9]+$/;
    return _reg.test(val);
}

/****验证密码规则****/
function testPassWord(val) {
    var _reg = /^[^\u4E00-\u9FA5]{6,16}$/;
    return _reg.test(val);
}

//获取数组索引
function getArrIndex(arr,val){
    for(var i=0,_len=arr.length;i<_len;i++){
        if(arr[i]==val){
            return i;
        }
    }
    return -1;
}

String.prototype.trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "");
};

String.prototype.ltrim = function () {
    return this.replace(/(^\s*)/g, "");
};

String.prototype.rtrim = function () {
    return this.replace(/(\s*$)/g, "");
};

/****过滤搜索字符串****/
function getSearchStr(val) {
    if (!val) {
        return '';
    } else {
        return val.replace(/[^A-Za-z_\u4e00-\u9fa50-9]/g, '');
    }
}

//验证数字
function testNumber(val) {
    var _reg = /^[0-9]+$/;
    return _reg.test(val);
}

/***验证ID（数字下划线）****/
function testID(val) {
    var _reg = /^[A-Za-z_0-9]+$/;
    return _reg.test(val);
}


/***验证真实姓名****/
function testRealName(val) {
    var _reg = /^[A-Za-z\u4e00-\u9fa5]+$/;
    return _reg.test(val);
}

/***验证手机号****/
function testPhone(val) {
    var _reg = /^1[34578]\d{9}$/;
    return _reg.test(val);
}

/***验证电子邮箱****/
function testEmail(val) {
    var _reg = /^([a-zA-Z0-9]+[|\|.])?[a-zA-Z0-9]+@([a-zA-Z0-9]+[|\|.]?)[a-zA-Z0-9]+.[a-zA-Z]{2,3}$/;
    return _reg.test(val);
}

/**验证单个ip以及多个ip逗号隔开**/
function testIps(val) {
    var _reg = /^((((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])),)*(((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))$/;
    return _reg.test(val);
}

/**验证单个ip**/
function testIp(val) {
    var _reg = /^(((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))$/;
    return _reg.test(val);
}

/**验证端口号**/
function testPort(val) {
    var _reg = /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/;
    return _reg.test(val);
}

//公用的正则方法
var regCommonFun = (function () {
    return {
        /**
         * 别名
         * @param val
         * @return {boolean}
         * @description 建议中英文数字下划线-
         * @author zhanghao
         *
         */
        testAlias: function (val) {
            var _reg = /^[A-Za-z_\u4e00-\u9fa50-9-]+$/;
            return _reg.test(val);
        },
        /**
         * 特殊别名  用户业务名称 需要加#
         * @param val
         * @return {boolean}
         * @description 建议中英文数字下划线-
         * @author zhanghao
         */
        testSpecialAlias: function (val) {
            var _reg = /^[A-Za-z_#\u4e00-\u9fa50-9-（）()]+$/;
            return _reg.test(val);
        },
        /**
         * 验证带HTTP或者HTTPS的IP可带端口号
         * @param val
         * @description
         * @return {boolean}
         * @author zhengtongwen
         */
        testIp: function (val) {
            var _reg = /^(http[s]*:\/\/)?(((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))(:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5]))?$/;
            return _reg.test(val);
        },
        /**
         * 强制IP+端口
         * @param val
         * @description
         * @return {boolean}
         * @author zhengtongwen
         */
        testHttpIpPort: function (val) {
            var _reg = /^(http[s]*:\/\/)(((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))(:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5]))$/;
            return _reg.test(val);
        },
        /**
         * 强制rtmp+IP+端口
         * @param val
         * @description
         * @return {boolean}
         * @author zhengtongwen
         */
        testRtmpIpPort: function (val) {
            var _reg = /^(rtmp:\/\/)(((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))(:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5]))$/;
            return _reg.test(val);
        },
        /**
         * 端口验证
         * @param val
         * @description 禁止输入汉字，标点，特殊字符，只可输入数字
         * @return {boolean}
         * @author zhanghao
         */
        testPort: function (val) {
            var _reg = /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/;
            return _reg.test(val);
        },
        /**
         * 验证IP格式开头的的地址路径
         * @param val
         * @returns {boolean}
         */
        testIpUrl: function (val) {
            var _reg = /^(http[s]*:\/\/)?(((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))(:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5]))?(\/[\da-zA-Z-_]+)*$/;
            return _reg.test(val);
        },
        /**
         * 验证手机号
         * @param val
         * @description 固定11位数，不限制格式
         * @return {boolean}
         * @author zhanghao
         */
        testPhone: function (val) {
            var _reg = /^1[123457890]\d{9}$/;
            return _reg.test(val);
        },
        /**
         * 验证图片后缀名
         * @param val
         * @return {boolean}
         * @author zhanghao
         */
        testPic: function (val) {
            var _reg = /.*(.jpg|.png)$/;
            return _reg.test(val);
        },
        /**
         * 验证登录名
         * @param val
         * @description 建议英文数字下划线
         * @return {boolean}
         * @author zhanghao
         */
        testLoginName: function (val) {
            var _reg = /^[A-Za-z_0-9]+$/;
            return _reg.test(val);
        },
        /**
         * 验证标题名称
         * @param val
         * @description 建议中英文数字
         * @return {boolean}
         * @author zhanghao
         */
        testTitleName: function (val) {
            var _reg = /^[A-Za-z0-9\u4e00-\u9fa5]+$/;
            return _reg.test(val);
        },
        /**
         * 验证生日（中文英文数字下划线）
         * @description yyyymmdd
         * @param val
         * @return {boolean}
         */
        testBirthDay: function (val) {
            var _reg = /^(19|20)\d{2}(1[0-2]|0?[1-9])(0?[1-9]|[1-2][0-9]|3[0-1])$/;
            var flag = _reg.test(val)
            return flag;
        },
        /****验证密码规则****/
        testPassWord: function (val) {
            var _reg = /^[^\u4E00-\u9FA5]{6,16}$/;
            return _reg.test(val);
        },
        /***验证电子邮箱****/
        testEmail: function (val) {
            var _reg = /^([a-zA-Z0-9]+[|\|.])?[a-zA-Z0-9]+@([a-zA-Z0-9]+[|\|.]?)[a-zA-Z0-9]+.[a-zA-Z]{2,3}$/;
            return _reg.test(val);
        },
    };
})();

//退出函数
function loginOut() {
    confirmDom('', function () {
        var _sendData = {
            businessKey: '',
            remarks: '',
            certificateIds: ''
        };

        if (window.location.pathname == '/remoteservice/user/main.do') {
            var oValue = getValue();
            _sendData.businessKey = oValue.taskId;
            _sendData.remarks = oValue.remarks;
            _sendData.certificateIds = oValue.certificateIds;

            //首页的全局变量是否再业务中
            if (bInTask) {
                var oUserInfo = getUserInfo();
                _sendData.applicantName = oUserInfo.userName;
                _sendData.sex = oUserInfo.userSex;
                _sendData.birthdate = oUserInfo.userBirthdate;
                _sendData.homeAddress = oUserInfo.userAddress;
                _sendData.IDNumber = oUserInfo.userNumber;
                _sendData.nation = oUserInfo.userMinzu;
                _sendData.phone = oUserInfo.userPhone;
                _sendData.educationId = oUserInfo.userEducation;
                _sendData.source = oUserInfo.userWhere;
            }
        }

        ajaxdata({url: 'user/logout.do'}, _sendData, function (result, data) {
            _sendData = null;
            if (result == 404) {
            } else {
                if (result) {
                    layer.close(zlayerIndex);
                    window.location.href = zBaseUrl + "user/index.do";
                } else {
                    layer.msg('退出失败，请稍后重试！');
                }
            }
        })
    })
}

//公用是否开始业务函数
function startMark() {
    return '<div id="start_mark" class="start-mark">\
              <div class="start-box">\
                <i class="start-icon"></i>\
                 <a class="start-btn sham-btn primary" id="start_mark_btn">开始受理业务</a>\
                </div>\
            </div>';
}

/**1
 * 获取所有业务类别
 * @param type 不传为全部,1为公安,2为社保
 * @param getClass 如果需要给页面中添加class调用回调函数（因为异步所以需要回调）
 */
function getBusinessTypeList(sendData, getClass) {
    ajaxdata({
        url: 'businessType/getBusinessType.do'
    }, {}, function (result, data) {
        getClass(data);
        //return data.data;
    })
}


//获取办理的业务类型
function getClassName(data, businessType) {
    var arr = [];
    businessType = businessType + '';
    if (businessType.substring(0, 1) == 1) {
        arr.push('公安类');
    } else if (businessType.substring(0, 1) == 2) {
        arr.push('社保类');
    }

    for (var i = 0; i < data.length; i++) {
        if (businessType == data[i].type) {
            arr.push(data[i].describes);
            break;
        }
    }
    return arr;
}

//判断是否是IE
function isIe() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if (isIE) {
        return true;
    } else if (isEdge) {
        return true;
    } else if (isIE11) {
        return true;
    } else {
        return false;
    }
}

//时间模块
setInterval(function () {
    setSysTime();
}, 1000);

setTimeout(function () {
    zBaseUrl = $('#basePath').attr('href');
    setSysTime();
    //渲染导航
    var role = $('#role_type').val(),
        oLogoTxt1 = $('#logo_txt1'),
        oLogoTxt2 = $('#logo_txt2');
    //根据用户权限显示二级Logo文字
    if (role == 'publicSecurity') {
        oLogoTxt2.find('.sys-version').show();
        oLogoTxt2.find('.logo-txt21').text($('#title_plolic').val());
    } else if (role == 'socialSecurity') {
        oLogoTxt2.find('.sys-version').show();
        oLogoTxt2.find('.logo-txt21').text($('#title_social').val());
    } else {
        oLogoTxt1.css('line-height', '55px');
        oLogoTxt1.find('.sys-version').show();
    }

    var addList = [
            {url: 'user/main.do', name: '远程受理'},
            {url: 'business/count.do', name: '业务统计'},
            {url: 'user/accountManage.do', name: '系统管理'},
            {url: 'statist/countChart.do', name: '数据中心'}],
        urlStr = '',
        oHeaderNav = $('#header_nav');
    if (role == 3) {
        urlStr = '<li class="handle-link"><a>远程受理</a></li>';
        oHeaderNav.html(urlStr);
    } else if (role == 1 || role == 2) {
        for (var i = 1; i < addList.length; i++) {
            urlStr += '<li class="admin-link' + i + '"><a href="' + addList[i].url + '">' + addList[i].name + '</a></li>';
        }
        oHeaderNav.html(urlStr);

        //如果IE678
        if (!jQuery.support.leadingWhitespace) {
            oHeaderNav.find('li:last-child').addClass('last-child');
        }
    }
}, 1);

function setSysTime() {
    var oYmd = $('#zymd'),
        oWeek = $('#zweek'),
        oTime = $('#ztime');
    var oTimeData = zGetYmdHms();
    oYmd.html(oTimeData.ymd);
    oWeek.html(oTimeData.week);
    oTime.html(oTimeData.hms);
}

/*****时间函数*****/
function zGetYmdHms() {
    var oDate = new Date();
    return {
        ymd: oDate.getFullYear() + '-' + zAddZero((oDate.getMonth() + 1)) + '-' + zAddZero(oDate.getDate()),
        week: '星期' + '日一二三四五六'.charAt(oDate.getDay()),
        hms: zAddZero(oDate.getHours()) + ':' + zAddZero(oDate.getMinutes()) + ':' + zAddZero(oDate.getSeconds())
    }
}

/***补零函数****/
function zAddZero(val) {
    if (val < 10) {
        return '0' + val;
    } else {
        return '' + val;
    }
}


/**
 * 字符串中的特殊字符
 * @param str  字符串
 * @param character 特殊字符不传默认为#
 */
function filterSpecialStr(str,character){
	if(!character){
		character = '#';
	}
	return str.replace(/#/g,'');
}

/*
 * 根据时间戳转换成具体时间
 */
function formatTime(timestamp) {
    // 先判断是否是空数据如果不为空转成数字，为空返回''
    if (filterEmptyValue(timestamp)) {
        timestamp = timestamp - 0;
        var time = new Date(timestamp),
            year = time.getFullYear(),
            month = time.getMonth() + 1,
            date = time.getDate(),
            hours = time.getHours(),
            minutes = time.getMinutes(),
            seconds = time.getSeconds();
        return {
            newymd: year + '年' + zAddZero(month) + '月' + zAddZero(date) + '日',
            ymd: year + '-' + zAddZero(month) + '-' + zAddZero(date),
            hms: zAddZero(hours) + ':' + zAddZero(minutes) + ':' + zAddZero(seconds),
            ymdHms: year + '-' + zAddZero(month) + '-' + zAddZero(date) + ' ' + zAddZero(hours) + ':' + zAddZero(minutes) + ':' + zAddZero(seconds)
        }
    } else {
        return {
            ymd: '',
            hms: '',
            ymdHms: ''
        }
    }
}

/**
 * 过滤空字符
 * @param value  值
 * @param isNumber 是否要转换number类型
 * @returns {*}
 */
function filterEmptyValue(value, isNumber) {
    if (!isNumber) {
        if (!value || value == 'undefined' || value == 'null') {
            return '';
        }
    } else {
        return 0;
    }
    return value;
}

/********公用loding层**********/
function lodingDom() {
    return layer.load(1, {
        shade: [0.3, '#000'], //0.1透明度的白色背景
        time: 9999999999999
    });
}

//询问层弹窗
function confirmDom(title, fnSuccess, fnEnd) {
    var _title = title ? title : '您确定要退出吗？';
    var _str = '<div class="zlayer">\
                <div class="zlayer-title">\
                    <span class="zlayer-title-txt">温馨提示</span>\
                    <i class="zlayer-title-close iconfont icon-close"></i>\
                </div>\
                <div class="zlayer-content confirm-box">\
                    <p class="confirm-txt">' + _title + '</p>\
                    <div class="zlayer-btn-box">\
                        <a class="sham-btn primary zlayer-btn-srue">确定</a>\
                        <a class="sham-btn danger zlayer-btn-cancel">取消</a>\
                    </div>\
                </div>\
            </div>';
    zlayerIndex = layer.open({
        type: 1,
        shade: [0.7],
        title: false,
        area: [],
        resize: false,
        scrollbar: false,
        shadeClose: false, //点击遮罩关闭
        content: _str,
        success: function () {
            $('.zlayer .icon-close,.zlayer-btn-cancel').click(function () {
                layer.close(zlayerIndex);
                if (fnEnd) {
                    fnEnd();
                }
            });
            $('.zlayer-btn-srue').click(function () {
                layer.close(zlayerIndex);
                if (fnSuccess) {
                    fnSuccess();
                }
            });
        }
    })
}
//询问层弹窗
function confirmDomSingleBtn(title, fnSuccess, fnEnd) {
    var _title = title ? title : '您确定要退出吗？';
    var _str = '<div class="zlayer">\
                <div class="zlayer-title">\
                    <span class="zlayer-title-txt">温馨提示</span>\
                    <i class="zlayer-title-close iconfont icon-close"></i>\
                </div>\
                <div class="zlayer-content confirm-box">\
                    <p class="confirm-txt">' + _title + '</p>\
                    <div class="zlayer-btn-box">\
                        <a class="sham-btn primary zlayer-btn-srue">确定</a>\
                    </div>\
                </div>\
            </div>';
    zlayerIndex = layer.open({
        type: 1,
        shade: [0.7],
        title: false,
        area: [],
        resize: false,
        scrollbar: false,
        shadeClose: false, //点击遮罩关闭
        content: _str,
        success: function () {
            $('.zlayer .icon-close,.zlayer-btn-cancel').click(function () {
                layer.close(zlayerIndex);
                if (fnEnd) {
                    fnEnd();
                }
            });
            $('.zlayer-btn-srue').click(function () {
                layer.close(zlayerIndex);
                if (fnSuccess) {
                    fnSuccess();
                }
            });
        }
    })
}
//询问层弹窗
function confirmDomDelFail(title,dataList, fnSuccess, fnEnd) {
    var _title = title ? title : '您确定要退出吗？';
    var _html = '';
    var _str = '<div class="zlayer">\
                <div class="zlayer-title">\
                    <span class="zlayer-title-txt">温馨提示</span>\
                    <i class="zlayer-title-close iconfont icon-close"></i>\
                </div>\
                <div class="zlayer-content confirm-box tips-renameList-content">\
                    <p class="confirm-txt">' + _title + '</p>\
                    <ul class="tips-renameList">';


        if(dataList.length > 0){
            for(var i=0,len=dataList.length;i<len;i++){
                var singleD = dataList[i];
                _str += '<li>'+singleD+'</li>'
            }
        }
    
         _str +=    '</ul>\
                    <div class="zlayer-btn-box">\
                        <a class="sham-btn primary zlayer-btn-srue">确定</a>\
                    </div>\
                </div>\
            </div>';
    zlayerIndex = layer.open({
        type: 1,
        shade: [0.7],
        title: false,
        area: [],
        resize: false,
        scrollbar: false,
        shadeClose: false, //点击遮罩关闭
        content: _str,
        success: function () {
            $('.zlayer .icon-close,.zlayer-btn-cancel').click(function () {
                layer.close(zlayerIndex);
                if (fnEnd) {
                    fnEnd();
                }
            });
            $('.zlayer-btn-srue').click(function () {
                layer.close(zlayerIndex);
                if (fnSuccess) {
                    fnSuccess();
                }
            });
        }
    })
}
/**
 * 视频播放弹层
 * @param option  参数比如视频名称，视频路径等
 * @param fnSuccess  回掉函数
 * @param fnEnd      回掉函数
 */
function palyVideo(videoOption, fnSuccess, fnEnd) {
    var _title = videoOption.videoName ? videoOption.videoName : '',
        oJwplay = null,
        _str = '<div class="zlayer">\
                <div class="zlayer-title">\
                    <span class="zlayer-title-txt">查看视频</span>\
                    <p class="zlayer-title-title">' + _title + '</p>\
                    <i class="zlayer-title-close iconfont icon-close"></i>\
                </div>\
                <div class="zlayer-content play-video-box">\
                    <div class="play-video" id="container"></div>\
                </div>\
            </div>';

    zlayerIndex = layer.open({
        type: 1,
        shade: [0.7],
        title: false,
        area: [],
        resize: false,
        scrollbar: false,
        shadeClose: false, //点击遮罩关闭
        content: _str,
        success: function () {
            $('.zlayer .icon-close,.zlayer-btn-cancel').click(function () {
                layer.close(zlayerIndex);
            });
            oJwplay = getJwplayer();
        }, end: function () {
            oJwplay.stop();
            oJwplay.pause(true);
            oJwplay = null;
            if (fnEnd) {
                fnEnd();
            }
        }
    });

    /**
     * 返回jwplay实例对象
     * @param obj  需要播放的父级
     * @param option  参数比例图片，视频路径，大小
     * @returns {*|void|undefined}
     */
    function getJwplayer() {
        return jwplayer('container').setup({
            //flashplayer: "resource/common/js/jwplayer/jwplayer.flash.swf", 不对
            file: videoOption.videoPath,
            width: '100%',  //屏幕可视区
            height: '100%',
            image: videoOption.videoImg,//视频预览图片
            dock: false,
            autostart: false,
            logo: {
                prefix: "resource/common/js/jwplayer",
                file: 'logo.png',
                link: 'http://www.visionvera.com/',
                hide: false,
                timeout: 10
            },
            rtmp: {
                bufferlength: 0.5
            }
        });
    }
}

//退出提示层
function logoOutMsg(title, fnSuccess, fnEnd) {
    var _title = title ? title : '您确定要退出吗？';
    var _str = '<div class="zlayer">\
                <div class="zlayer-title">\
                    <span class="zlayer-title-txt">温馨提示</span>\
                </div>\
                <div class="zlayer-content loginout-txt-box">\
                    <p class="loginout-txt-title">' + _title + '</p>\
                    <p class="loginout-txt-time"><span id="loginout_time" class="">5</span>秒后返回首页!</p>\
                </div>\
            </div>';
    zlayerIndex = layer.open({
        type: 1,
        shade: [0.7],
        title: false,
        area: [],
        resize: false,
        scrollbar: false,
        shadeClose: false, //点击遮罩关闭
        content: _str,
        success: function () {
            $('.zlayer .icon-close,.zlayer-btn-cancel').click(function () {
                layer.close(zlayerIndex);
            });
            $('.zlayer-btn-srue').click(function () {
                if (fnSuccess) {
                    fnSuccess();
                }
            });
            var oLoginTime = $('#loginout_time'),
                nEndTime = 5;
            setInterval(function () {
                if (nEndTime >= 1) {
                    oLoginTime.html(--nEndTime);
                } else {
                    window.location.href = zBaseUrl + "user/index.do";
                }
            }, 1000);

        }, end: function () {
            if (fnEnd) {
                fnEnd();
            }
        }
    })
}

/**
 * 图片弹层组件
 * @param _url 要点击的图片的url
 */
function layerImage(_url) {
    var oImage = null,
        _str = '<div id="zlayer_imgage_wrap">\
                    <div id="zlayer_imgage_mark"></div>\
                    <span class="imgage-span"></span>\
                    <div class="imgage-img-box">\
                        <img class="imgage-img" src="' + _url + '" alt="">\
                        <i class="imgage-close"></i>\
                     </div>\
                </div>';
    $('body').append(_str);
    oImage = $('#zlayer_imgage_wrap');
    oImage.click(function (e) {
        var e = e || window.event;
        if ($(e.target).attr('id') == 'zlayer_imgage_mark' || $(e.target).hasClass('imgage-close')) {
            oImage.remove();
        } else {
            return;
        }
    })
}


$(function () {
    if (!('placeholder' in document.createElement('input'))) {
        $('input[placeholder],textarea[placeholder]').each(function () {
            var that = $(this),
                text = that.attr('placeholder');
            if (that.val() === "") {
                that.val(text).addClass('placeholder');
            }
            that.focus(function () {
                if (that.val() === text) {
                    that.val("").removeClass('placeholder');
                }
            })
                .blur(function () {
                    if (that.val() === "") {
                        that.val(text).addClass('placeholder');
                    }
                })
                .closest('form').submit(function () {
                if (that.val() === text) {
                    that.val('');
                }
            });
        });
    }
});

var privateFun = (function () {
    return {
        data: {
            _indexLayerAccount: null,//弹窗
        },
        /**
         * 查询详情
         * @param _this
         * @param type  1、中心管理   2、用户  3、设备 4、终端
         */
        searchDetails: function (dom, type) {
            var _this = this,
                id = $(dom).data('id'),
                urlData,
                sendData;

            if (!id) return;

            switch (type) {
                case 1:
                    urlData = {url: "serviceCenter/getServiceCenterList.do"};
                    sendData = {serviceId: id};
                    break;
                case 2:
                    urlData = {url: "user/getUserList.do"};
                    sendData = {userId: id};
                    break;
                case 3:
                    urlData = {url: 'deviceInfo/getdeviceDetail.do'};
                    sendData = {deviceId: id};
                    break;
                case 4:
                    urlData = {url: 'vcDev/getDeviceList.do',};
                    sendData = {id: id};
                    break;
            }
            ajaxdata(urlData, sendData, function (result, data) {
                if (result == 404) {
                } else {
                    if (result) {
                        _this.saveDetails(type, data);
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
        },
        saveDetails: function (type, data) {
            if (!data) return;
            var detailData;
            switch (type) {
                case 1:
                    detailData = data.resultList.list[0];
                    var centerObj = this.saveDetailsCenter(detailData);
                    if (centerObj) this.centerDetails(centerObj);
                    break;
                case 2:
                    detailData = data.resultList.list[0];
                    var userObj = this.saveDetailsUser(detailData);
                    if (userObj) this.userDetails(userObj);
                    break;
                case 3:
                    detailData = data.data;
                    var deviceObj = this.saveDetailsDevice(detailData);
                    if (deviceObj) this.deviceDetails(deviceObj);
                    break;
                case 4:
                    detailData = data.resultList.list[0];
                    var terminalObj = this.saveDetailsTerminal(detailData);
                    if (terminalObj) this.terminalDetails(terminalObj);
                    break;
            }
        },
        /**
         * 设备详情
         */
        saveDetailsDevice: function (detailData) {
            var obj = new Object();
            obj.type = detailData.type ? this.deviceTypeFilter(detailData.type) : "";
            obj.roleType = detailData.printerType == '' ? 1 : detailData.printerType;
            obj.deviceName = detailData.deviceName ? filterEmptyValue(detailData.deviceName) : "";
            obj.privateName = detailData.privateName ? filterEmptyValue(detailData.privateName) : "";
            obj.ip = detailData.ip ? detailData.ip : "";
            obj.port = detailData.port ? detailData.port : "";
            obj.status = (detailData.status || detailData.status === 0) ? this.deviceStatusTypeFilter(detailData.status - 0) : "";
            obj.address = detailData.address ? detailData.address : "";
            return obj;
        },
        /**
         * 存储终端详情
         * @param detailData
         */
        saveDetailsTerminal: function (detailData) {
            var obj = new Object();
            obj.terminalId = detailData.id ? filterEmptyValue(detailData.id) : "";
            obj.terminalName = detailData.name ? filterEmptyValue(detailData.name) : "";
            obj.terminalIP = detailData.ip ? filterEmptyValue(detailData.ip) : "";
            obj.terminalMac = detailData.mac ? filterEmptyValue(detailData.mac) : "";
            obj.terminalUserId = detailData.userId ? filterEmptyValue(detailData.userId) : "";
            obj.terminalServiceKey = detailData.serviceKey ? filterEmptyValue(detailData.serviceKey) : "";
            obj.terminalForm = (detailData.form || detailData.form === 0) ? bindType(filterEmptyValue(detailData.form) - 0) : "";
            obj.terminalAffiliation = detailData.affiliation ? filterEmptyValue(detailData.affiliation) : "";
            obj.terminalState = (detailData.state || detailData.state === 0) ? this.terminalStateTypeFilter(detailData.state) : "";
            return obj;
        },
        /**
         * 中心管理详情
         * @param detailData
         */
        saveDetailsCenter: function (detailData) {
            var obj = new Object();
            obj.centerName = detailData.serviceName ? filterEmptyValue(detailData.serviceName) : "";
            obj.centerGuishu = detailData.parentName ? filterEmptyValue(detailData.parentName) : "";
            obj.centerXingzhengquyu = detailData.regionAll ? filterEmptyValue(detailData.regionAll) : "";
            obj.centerDizhi = detailData.address ? filterEmptyValue(detailData.address) : "";
            obj.centerJibie = detailData.gradeId == 5 ? '服务中心' : '审批中心';
            obj.centerTime = detailData.updateTime ? formatTime(filterEmptyValue(detailData.updateTime)).ymdHms : "";
            obj.centerStatus = (detailData.status || detailData.status === 0) ? zServerCenter.getStatus(detailData.status) : "";
            return obj;
        },
        /**
         * 用户详情
         * @param detailData
         */
        saveDetailsUser: function (detailData) {
            var obj = new Object();
            obj.loginName = detailData.loginName ? filterEmptyValue(detailData.loginName) : "";
            obj.userName = detailData.userName ? filterEmptyValue(detailData.userName) : "";
            obj.roleId = detailData.roleList[0].roleId ? userRoleFilter(filterEmptyValue(detailData.roleList[0].roleId)) : "";
            obj.mobilePhone = detailData.mobilePhone ? filterEmptyValue(detailData.mobilePhone) : "";
            obj.email = detailData.email ? filterEmptyValue(detailData.email) : "";
            obj.workStatus = (detailData.workStatus || detailData.workStatus === 0) ? workStatus(detailData.workStatus) : "";
            return obj;
        },
        /**
         * 查看详情的窗口
         * @param type
         * @param el
         * @author zhanghao
         */
        terminalDetails: function (obj) {
            var _this = this;
            // _this.data._equipmentId = $.cookie("serviceKey"); //设备ID
            // _this.data._equipmentAffiliation = $.cookie("serviceName"); //归属名称


            _addUserAccountSir = '<div class="zlayer">\
		    <div class="zlayer-title">\
		        <span class="zlayer-title-txt">查看详情</span>\
		        <i class="zlayer-title-close iconfont icon-close"></i>\
		    </div>\
		    <div class="zlayer-content add-terminal see-terminal-height">\
			        <div class="add-item-box">\
		            <div class="add-item fr">\
		                <label class="add-item-txt">终端ID</label>\
		                <input value="' + obj.terminalId + '" class="add-item-info stopMody" type="text" disabled>\
		            </div>\
		            <div class="add-item fl" id="of_name_box">\
	            		<label class="add-item-txt">终端名称</label>\
		                <input value="' + obj.terminalName + '" class="add-item-info stopMody" type="text" disabled>\
		        	</div>\
		        </div>\
		        <div class="add-item-box" id="area_box">\
		            <div class="add-item fl">\
		                <label class="add-item-txt">终端IP</label>\
		                <input class="add-item-info stopMody" type="text" value="' + obj.terminalIP + '" disabled>\
		            </div>\
		            <div class="add-item fr">\
		                <label class="add-item-txt ">终端mac</label>\
		                <input class="add-item-info stopMody" type="text" value="' + obj.terminalMac + '" disabled>\
		            </div>\
		        </div>\
			        <div class="add-item-box">\
			        	<div class="add-item fl">\
			        		<label class="add-item-txt">归属</label>\
			        		<input class="add-item-info stopMody" type="text" value="' + obj.terminalAffiliation + '" disabled>\
			        	</div>\
		           	<div class="add-item fr">\
			        	<label class="add-item-txt ">归属类别</label>\
			        	<input class="add-item-info stopMody" type="text" value="' + obj.terminalForm + '" disabled>\
			        </div>\
		        </div>\
		        <div class="add-item-box">\
		            <div class="add-item fl">\
			        		<label class="add-item-txt">状态</label>\
			        		<input class="add-item-info stopMody" type="text" value="' + obj.terminalState + '" disabled>\
                    </div>\
		        </div>\
		    </div>\
		</div>';

            _this.data._indexLayerAccount = layer.open({
                type: 1,
                shade: [0.7],
                title: false,
                area: ['auto', 'auto'],
                resize: false,
                scrollbar: false,
                shadeClose: false, //点击遮罩关闭
                content: _addUserAccountSir,
                success: function () {
                    $('.zlayer .icon-close,.zlayer-btn-cancel').click(function () {
                        layer.close(_this.data._indexLayerAccount);
                    });
                },
                end: function () {
                    layer.close(_this.data._indexLayerAccount);
                }
            });

        },
        /**
         * 中心管理查看详情的窗口
         * @param type
         * @param el
         * @author zhanghao
         */
        centerDetails: function (obj) {
            var _this = this;

            _addUserAccountSir = '<div class="zlayer">\
		    <div class="zlayer-title">\
		        <span class="zlayer-title-txt">查看详情</span>\
		        <i class="zlayer-title-close iconfont icon-close"></i>\
		    </div>\
		    <div class="zlayer-content add-terminal see-center-height">\
                <div class="add-item-box">\
		            <div class="add-item fr">\
		                <label class="add-item-txt">中心名称</label>\
		                <input value="' + obj.centerName + '" class="add-item-info stopMody" type="text" disabled>\
		            </div>\
		            <div class="add-item fl" id="of_name_box">\
	            		<label class="add-item-txt">归属审批中心</label>\
	            		<input value="' + obj.centerGuishu + '" class="add-item-info stopMody" type="text" disabled>\
		        	</div>\
		        </div>\
			        <div class="add-item-box">\
			        	<div class="add-item fl">\
			        		<label class="add-item-txt">行政区域</label>\
			        		<input class="add-item-info stopMody" type="text" value="' + obj.centerXingzhengquyu + '" disabled>\
			        	</div>\
		           	<div class="add-item fr">\
			        	<label class="add-item-txt ">中心类别</label>\
                        <input class="add-item-info stopMody" type="text" value="' + obj.centerJibie + '" disabled>\
			        </div>\
		        </div>\
		        <div class="add-item-box">\
		            <div class="add-item fl">\
			        		<label class="add-item-txt">上次编辑时间</label>\
			        		<input class="add-item-info stopMody" type="text" value="' + obj.centerTime + '" disabled>\
                    </div>\
			        <div class="add-item fr">\
			        	<label class="add-item-txt ">状态</label>\
		        		<input class="add-item-info stopMody" type="text" value="' + obj.centerStatus + '" disabled>\
			        </div>\
		        </div>\
		        <div class="add-item-box">\
		            <div class="add-item fl">\
		                <label class="add-item-txt">地址</label>\
		                <input class="add-item-info w588 stopMody" type="text" value="' + obj.centerDizhi + '" disabled>\
		            </div>\
		        </div>\
		    </div>\
		</div>';

            _this.data._indexLayerAccount = layer.open({
                type: 1,
                shade: [0.7],
                title: false,
                area: ['auto', 'auto'],
                resize: false,
                scrollbar: false,
                shadeClose: false, //点击遮罩关闭
                content: _addUserAccountSir,
                success: function () {
                    $('.zlayer .icon-close,.zlayer-btn-cancel').click(function () {
                        layer.close(_this.data._indexLayerAccount);
                    });

                },
                end: function () {

                    layer.close(_this.data._indexLayerAccount);
                }
            });

        },
        /**
         * 中心管理查看详情的窗口
         * @param type
         * @param el
         * @author zhanghao
         */
        userDetails: function (obj) {
            var _this = this;

            _addUserAccountSir = '<div class="zlayer">\
		    <div class="zlayer-title">\
		        <span class="zlayer-title-txt">查看详情</span>\
		        <i class="zlayer-title-close iconfont icon-close"></i>\
		    </div>\
		    <div class="zlayer-content add-terminal see-user-height">\
			        <div class="add-item-box">\
		            <div class="add-item fr">\
		                <label class="add-item-txt">用户名称</label>\
		                <input value="' + obj.loginName + '" class="add-item-info stopMody" type="text" disabled>\
		            </div>\
		            <div class="add-item fl" id="of_name_box">\
	            		<label class="add-item-txt">姓名</label>\
	            		<input value="' + obj.userName + '" class="add-item-info stopMody" type="text" disabled>\
		        	</div>\
		        </div>\
			        <div class="add-item-box">\
			        	<div class="add-item fl">\
			        		<label class="add-item-txt">手机号</label>\
			        		<input class="add-item-info stopMody" type="text" value="' + obj.mobilePhone + '" disabled>\
			        	</div>\
		           	<div class="add-item fr">\
			        	<label class="add-item-txt ">电子邮箱</label>\
			        	<input class="add-item-info stopMody" type="text" value="' + obj.email + '" disabled>\
			        </div>\
		        </div>\
		        <div class="add-item-box">\
		            <div class="add-item fl">\
			        		<label class="add-item-txt">角色</label>\
			        		<input class="add-item-info stopMody" type="text" value="' + obj.roleId + '" disabled>\
                    </div>\
			        <div class="add-item fr">\
			        	<label class="add-item-txt ">状态</label>\
			        	<input class="add-item-info stopMody" type="text" value="' + obj.workStatus + '" disabled>\
			        </div>\
		        </div>\
		    </div>\
		</div>';

            _this.data._indexLayerAccount = layer.open({
                type: 1,
                shade: [0.7],
                title: false,
                area: ['auto', 'auto'],
                resize: false,
                scrollbar: false,
                shadeClose: false, //点击遮罩关闭
                content: _addUserAccountSir,
                success: function () {
                    $('.zlayer .icon-close,.zlayer-btn-cancel').click(function () {
                        layer.close(_this.data._indexLayerAccount);
                    });

                },
                end: function () {

                    layer.close(_this.data._indexLayerAccount);
                }
            });

        },
        /**
         * 设备详情
         * @param obj
         */
        deviceDetails: function (obj) {

            obj.serviceKey = $.cookie("serviceKey"); //设备ID
            obj.serviceName = $.cookie("serviceName"); //归属名称

            if (obj.type == '打印机') {

                obj.roleTypeName = '';

                //转换成打印机角色名称
                for (var i = 0; i < oEquipment.data._equipmentRole.length; i++) {
                    if (oEquipment.data._equipmentRole[i].commonValue == obj.roleType) {
                        obj.roleTypeName = oEquipment.data._equipmentRole[i].describes;
                    }
                }
            }

            _addUserAccountSir = '<div class="zlayer">\
		    <div class="zlayer-title">\
		        <span class="zlayer-title-txt">查看详情</span>\
		        <i class="zlayer-title-close iconfont icon-close"></i>\
		    </div>\
		    <div class="zlayer-content add-terminal see-equipment-height">\
		        <div class="add-item-box">\
		        <div class="add-item fl">\
	                <label class="add-item-txt">类型</label>\
	                <input value="' + obj.type + '" class="add-item-info stopMody" type="text" disabled>\
	            </div>\
	            <div class="add-item fr" id="roleTypeBox">\
                <label class="add-item-txt">打印机角色</label>\
	                <input value="' + obj.roleTypeName + '" class="add-item-info stopMody" type="text" disabled>\
	            </div>\
			        </div>\
			        <div class="add-item-box">\
		            <div class="add-item fr">\
		                <label class="add-item-txt">归属</label>\
		                <input data-id="' + obj.serviceKey + '" value="' + obj.serviceName + '" class="add-item-info stopMody" type="text" disabled>\
		            </div>\
		            <div class="add-item fl" id="of_name_box">\
	            		<label class="add-item-txt">设备名称</label>\
	            		<input value="' + obj.deviceName + '" class="add-item-info stopMody" type="text" disabled>\
		        	</div>\
		        </div>\
		        <div class="add-item-box" id="area_box">\
		            <div class="add-item fl">\
		                <label class="add-item-txt">IP</label>\
		                <input class="add-item-info stopMody" type="text" id="equipmentIp" value="' + obj.ip + '" disabled>\
		            </div>\
		            <div class="add-item fr">\
		                <label class="add-item-txt ">端口</label>\
		                <input class="add-item-info stopMody" type="text" id="equipmentPort" value="' + obj.port + '" disabled>\
		            </div>\
		        </div>\
			        <div class="add-item-box" id="area_box">\
			        	<div class="add-item fl">\
			        		<label class="add-item-txt">别名</label>\
			        		<input class="add-item-info stopMody" type="text" id="equipmentPrivateName" value="' + obj.privateName + '" disabled>\
			        	</div>\
		           	<div class="add-item fr">\
			        	<label class="add-item-txt ">状态</label>\
			        	<input class="add-item-info stopMody" type="text" id="equipmentPrivateName" value="' + obj.status + '" disabled>\
			        </div>\
		        </div>\
		        <div class="add-item-box">\
		            <div class="add-item fl">\
		                <label class="add-item-txt">详细地址</label>\
		                <input class="add-item-info w588 stopMody" id="equipmentAddressInfo" type="text" value="' + obj.address + '" disabled>\
		            </div>\
		        </div>\
		    </div>\
		</div>';

            oEquipment.data._indexLayerAccount = layer.open({
                type: 1,
                shade: [0.7],
                title: false,
                area: ['auto', 'auto'],
                resize: false,
                scrollbar: false,
                shadeClose: false, //点击遮罩关闭
                content: _addUserAccountSir,
                success: function () {

                    var oRoleTypeDom = $('#roleTypeBox');
                    if (obj.type != '打印机') {
                        oRoleTypeDom.hide();
                    }

                    $('.zlayer .icon-close,.zlayer-btn-cancel').click(function () {
                        layer.close(oEquipment.data._indexLayerAccount);
                    });
                },
                end: function () {
                    layer.close(oEquipment.data._indexLayerAccount);
                }
            });

        },
        /**
         * 根据值返回对应的中文
         * @param val
         */
        terminalStateTypeFilter: function (val) {
            var text;
            switch (val * 1) {
                case 0:
                    text = '空闲';
                    break;
                case 1:
                    text = '使用中';
                    break;
            }
            return text;
        },
        /**
         * 设备类型过滤
         * @param val
         * @return {*}
         */
        deviceTypeFilter: function (val) {
            var text;
            switch (val) {
                case '01':
                    return 'pad';
                    break;
                case '02':
                    return '一体机';
                    break;
                case '03':
                    text = '打印机';
                    break;
                default:
                    text = '无';
                    break;
            }
            return text;
        },
        /**
         * 设备状态类型过滤
         * @param val
         * @return {*}
         */
        deviceStatusTypeFilter: function (val) {
            var text;
            switch (val * 1) {
                case 0:
                    text = '可用';
                    break;
                case 2:
                    text = '不可用';
                    break;
            }
            return text;
        },
    }
})();

/**
 * 图片预览的弹窗类
 * @param dom img图片的dom名称 不用加#或者.
 * @param src 默认图片路径
 * @param type 表单还是图片
 * @param formImgs 所有的表单图片
 * @param flag 是否需要签名
 * @author zhanghao
 */
var PicPreview = function (businessKey, dom, src, type, formImgs, flag) {
    // this.picDom = dom;
    var _this = this;
    this.container = dom;
    this.picURL = src + "?date=" + new Date().getTime();
    this.flag = flag ? flag : false;
    this.formImgs = formImgs;
    this.businessKey = businessKey;
    this.type = type;
    this.selectedDom = [];//印章和签名选中后加入这里

    this.init();

};
PicPreview.prototype.init = function () {
//    暂时先用dom 后期改成字符串生成dom

    this.createPopup();//创建html


    this.plugnInInit();

    //是否需要签名  不需要签名隐藏
    if (!this.flag) {
        $("#formAutograph").hide();
    }

    if (this.type.toUpperCase() === 'FORM') {
        //    表单 多四个按钮
        $(".form-create-nav").show();
        $('.pic-browser').height('600');

    } else if (this.type.toUpperCase() === 'IMAGE') {
        //    图片
        $(".form-create-nav").hide();
        $('.pic-browser').height('520');
    }


    this.addEvent();
};
PicPreview.prototype.plugnInInit = function () {
    var _this = this;
    this.container = $$(this.container);
    // this.picURL = src+"?date="+new Date();
    this.options = {
        onPreLoad: function () {
            _this.container.style.backgroundImage = "";
        },
        onLoad: function () {
            _this.container.style.backgroundImage = "";
        },
        onError: function (err) {
            _this.container.style.backgroundImage = "";
            // alert(err)
        }
    };

    this.imgFun = new ImageTrans(this.container, this.options);
    this.imgFun.load(this.picURL);
    var imgShellW =  $('#imgShell').width();
    $('#imgShell img').prop('width',imgShellW);
};
PicPreview.prototype.createPopup = function () {
    var html = ['<div class="layer-myPreview" id="layer_myPreview">',
        '        <div class="layer-myPreview-bg"></div>',
        '        <div id="pic_browser" class="pic-browser">',
        '            <div class="header-shell">',
        '                <i class="pic-preview-close" id="pic_close"></i>',
        '                <h2 class="header-title" id="popupTitle">图片预览</h2>',
        '            </div>',
        '            <div class="img-shell" id="imgShell">',
        '            </div>',
        '            <div class="pic-fun-group-shell">',
        '                <a href="javascript:;" class="pic-fun-icon icon-left" id="rotateLeft"></a>',
        '                <a href="javascript:;" class="pic-fun-icon icon-right" id="rotateRight"></a>',
        '                <a href="javascript:;" class="pic-fun-icon icon-shuoxiao" id="rotateNarrow" title="zoom out" alt="zoom out" ></a>',
        '                <a href="javascript:;" class="pic-fun-icon icon-fangda" id="rotateEnlarge" title="zoom in" alt="zoom in" ></a>',
        '                <a href="javascript:;" class="pic-fun-icon icon-reset" id="imgReset" title="zoom in" alt="zoom in" ></a>',
        '            </div>',
        '            <div class="form-create-nav">',
        '                <a href="javascript:;" class="form-pic-group" id="formAutograph">申请人签名</a>',
        '                <a href="javascript:;" class="form-pic-group" id="formChapter">加盖公章</a>',
        '                <a href="javascript:;" id="formLocal" data-id="1">本地打印</a>',
        '                <a href="javascript:;" id="formRotate" data-id="2">远程打印</a>',
        '            </div>',
        '        </div>',
        '    </div>'].join("");
    $("body").append(html);
    // return html;
};
PicPreview.prototype.addEvent = function () {
    // var value2 = 0;
    console.log(this.formImgs);
    var _this = this;
    $$("rotateLeft").onclick = function () {
        _this.imgFun.left();
    } //左转
    $$("rotateRight").onclick = function () {
        _this.imgFun.right();
    } //右转
    $$("rotateEnlarge").onclick = function () {
        _this.imgFun.zoomin();
    } //放大
    $$("rotateNarrow").onclick = function () {
        _this.imgFun.zoomout();
    } //缩小
    $$("imgReset").onclick = function () {
        _this.imgFun.reset();
    }
    $$("pic_close").onclick = function () {
        _this.destroy();
    }


    if (this.type.toUpperCase() === "FORM") {
        // formAutograph 申请人签名 formChapter 加盖公章 formLocal 本地打印  formRotate 远程打印
        $("#formAutograph").click(function () {
            // this.imgFun.load(this.picURL);
            if (_this.formImgs.signPath) {

                if ($(this).hasClass('active')) {
                    // $(".form-pic-group")
                    $(this).removeClass('active').html('申请人签名');

                    // _this.selectedDom.splice()
                    for (var i = 0; i < _this.selectedDom.length; i++) {

                        if (_this.selectedDom[i] === $(this).index()) {
                            _this.selectedDom.splice(i, 1);
                        }
                    }
                    console.log(_this.selectedDom);
                    if (_this.selectedDom.length === 0) {
                        _this.imgFun.load(_this.formImgs.imagePath);
                    } else {
                        _this.imgFun.load(_this.formImgs.stampPath);
                    }

                    // _this.imgFun.load(_this.formImgs.imagePath);


                } else {
                    $(this).addClass('active').html('撤销申请人签名');
                    _this.selectedDom.push($(this).index());
                    if (_this.selectedDom.length === 2) {
                        _this.imgFun.load(_this.formImgs.stampAndSignPath);
                    } else {
                        _this.imgFun.load(_this.formImgs.signPath);
                    }


                }

            }
        });


        $("#formChapter").click(function () {
            if (_this.formImgs.stampPath) {
                if ($(this).hasClass('active')) {
                    // $(".form-pic-group")
                    $(this).removeClass('active').html('加盖公章');
                    for (var i = 0; i < _this.selectedDom.length; i++) {
                        if (_this.selectedDom[i] === $(this).index()) {
                            _this.selectedDom.splice(i, 1);
                        }
                    }
                    console.log(_this.selectedDom);
                    if (_this.selectedDom.length === 0) {
                        _this.imgFun.load(_this.formImgs.imagePath);
                    } else {
                        _this.imgFun.load(_this.formImgs.signPath);
                    }

                    // _this.imgFun.load(_this.formImgs.imagePath);

                } else {
                    $(this).addClass('active').html('撤销加盖公章');
                    // _this.imgFun.load(_this.formImgs.stampPath);
                    _this.selectedDom.push($(this).index());
                    if (_this.selectedDom.length === 2) {
                        _this.imgFun.load(_this.formImgs.stampAndSignPath);
                    } else {
                        _this.imgFun.load(_this.formImgs.stampPath);
                    }
                }
                // _this.imgFun.load(this.formImgs.stampPath);
            }
        });

        $("#formLocal").click(function () {

            //本地打印
            submitPrint(false);
        });

        $("#formRotate").click(function () {
            //远程打印
            submitPrint(true);
        });


        function submitPrint(flag) {
            var sendData = {
                businessKey: _this.businessKey,
                sing: false,
                print: flag,
                stamp: false
            };
            for (var i = 0; i < _this.selectedDom.length; i++) {
                if (_this.selectedDom === 0) {
                    sendData.sing = true;
                } else if (_this.selectedDom === 1) {
                    sendData.stamp = true;
                }
            }
            ajaxdata({url: "business/dataPrint.do"}, sendData, function (result, data) {
                if (result) {
                    console.log(data);
                    layer.msg(data.msg);
                } else {
                    layer.msg(data.msg);
                }
            })
        }
    }
};
PicPreview.prototype.destroy = function () {
    this.imgFun.dispose();//销毁插件
    $("#layer_myPreview").remove();
};

/**
 * business/getPrintscreenList.do
 *
 * businessKey  pictureType 21
 */
